import React from 'react';
import CommonList from '../../../components/CommonLists/list';
import { Button, message } from 'antd';

class IndicatorList extends CommonList {
  constructor(props) {
    super(props);
    this.api = 'indicator';
    this.state = {
      applications: [],
    };
    this.operatorWidth = 150;
    this.editButton = (record) => {
      return (
        <Button
          size='small'
          type='link'
          disabled={record.audit_status === this.AUDIT._WAIT}
          onClick={this.edit.bind(this, record, { title: '编辑指标' })}
        >
          编辑
        </Button>
      );
    };

    this.copyButton = (record) => {
      return (
        <Button
          size='small'
          type='link'
          onClick={this.copy.bind(this, record)}
          disabled={record.audit_status === this.AUDIT._WAIT}
        >
          复制
        </Button>
      );
    };

    this.delButton = (record) => {
      return (
        <Button
          size='small'
          type='link'
          onClick={this.deleteConfirm.bind(this, record)}
          disabled={record.audit_status === this.AUDIT._WAIT}
        >
          删除
        </Button>
      );
    };

    this.verButton = (record) => {
      return (
        <Button
          size='small'
          type='link'
          onClick={this.openVersion.bind(this, record.feature_id)}
          disabled={record.audit_status === this.AUDIT._WAIT}
        >
          版本
        </Button>
      );
    };
    this.btnGroup = [this.editButton, this.copyButton, this.delButton, this.verButton];
  }
  componentDidMount() {}

  // 删除时的参数
  getDeleteParam = (record) => {
    return { feature_id: record.feature_id };
  };

  // deleteConfirm
  deleteConfirm(record) {
    if (record.strategy_count > 0) {
      message.error(`有${record.strategy_count}条策略使用了此指标，请先下线关联策略再删除此指标！`);
      return;
    }
    this.delete(record);
  }

  // 打开新版本
  openVersion = (id) => {
    this.props.history.push(`/variable/indicator/${id}/version`);
  };
}

export default IndicatorList;
